import {defineConfig, externalizeDepsPlugin, loadEnv} from "electron-vite";
import {resolve} from "path";
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";
import vueDevTools from "vite-plugin-vue-devtools";


export default defineConfig(({command, mode}) => {
    const env = loadEnv(mode);
    console.log(resolve(__dirname, 'src/renderer/main-window.html'), "file name")
    return {
        main: {
            plugins: [externalizeDepsPlugin()],
            resolve: {
                alias: {
                    '@': resolve('src'),
                }
            },
            build: {
                rollupOptions: {
                    input: {
                        main: resolve(__dirname, 'src/main/main.js'),
                    }
                }
            }

        },
        preload: {
            plugins: [externalizeDepsPlugin()],
            resolve: {
                alias: {
                    '@': resolve('src'),
                }
            },
            build: {
                rollupOptions: {
                    input: {
                        mainWindow: resolve(__dirname, 'src/preload/preload-main-window.js'),
                        dynamicWindow: resolve(__dirname, 'src/preload/preload-main-window.js'),
                    }
                }
            }
        },
        renderer:
            {
                __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: 'true',
                resolve: {
                    alias: {
                        '@renderer': resolve('src/renderer'),
                        '@': resolve('src'),
                        '@main-window': resolve('src/renderer/main-window'),
                        '@share': resolve('src/renderer/share'),
                    }
                },
                plugins: [
                    vue(),
                    vueJsx(),
                    vueDevTools(),
                ],
                server: {
                    port: env.VITE_DEV_PORT,
                    host: env.VITE_DEV_HOST,
                    static: {
                        directory: resolve(__dirname, 'src/renderer/public')
                    }
                },
                build: {
                    rollupOptions: {
                        input: {
                            mainWindow: resolve(__dirname, 'src/renderer/main-window.html'),
                            dynamicWindow: resolve(__dirname, 'src/renderer/dynamic-window.html'),
                        }
                    }
                },
            }
    }
})

